package com.hd.common.page;

import com.hd.auth.sdk.model.User;
import com.hd.auth.sdk.util.AuthUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


/**
 * 控制类基类
 */
@RestController
public abstract class BaseController {

    protected final static Logger LOGGER = LoggerFactory.getLogger(BaseController.class);

    @Autowired
    private AuthUtils AuthUtils;

    @Autowired
    private HttpServletRequest request;

    protected User getCurrentUser() {
        return AuthUtils.getLoginUser(request);
    }

    protected List<String> getCurrentStationIds() {
        List<String> stations = new ArrayList<>();
        User user = getCurrentUser();
        if (user != null && user.getDeptIdList() != null && user.getDeptIdList().size() > 0) {
            stations = user.getDeptIdList();
        }
        return stations;
    }
}
